package com.myapp.ruyixing.http;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import com.myapp.ruyixing.model.Privilege;

public class PrivilegeParser extends RYJSONParser {

	@Override
	public Object parse(JSONObject jsonObject) {
		if (getErrno(jsonObject) != NO_ERROR) {
			return null;
		}

		JSONObject data = jsonObject.optJSONObject("data");
		JSONArray items = data.optJSONArray("items");
		
		Privilege privilege = new Privilege();
		privilege.items = new ArrayList<Privilege.PrivilegeItem>();

		if (items != null) {
			for (int i = 0; i < items.length(); i++) {
				Privilege.PrivilegeItem privilegeItem = new Privilege.PrivilegeItem();
				JSONObject item = items.optJSONObject(i);
				
				privilegeItem.id = item.optString("id");
				privilegeItem.name = item.optString("title");
				privilegeItem.recommend = item.optString("recommend");
				privilegeItem.labels = item.optString("labels");
				privilegeItem.distance = item.optLong("distance");
				privilegeItem.picUrl = item.optString("picurl");
				

				privilegeItem.activitytime = item.optString("activitytime");
				privilegeItem.hots = item.optString("hots");
				privilegeItem.signup = item.optString("signup");
				privilegeItem.originalprice = item.optString("originalprice");
				privilegeItem.presentprice = item.optString("presentprice");
				
				
				privilege.items.add(privilegeItem);
			}
		}
		
		return privilege;
	}
}
